import time

from Page1 import Page1
from selenium.webdriver.common.by import By
class Page2(Page1):
    # 搜索商品
    search_loc=(By.XPATH,'//*[@id="wd"]')
    def search(self):
        self.send_keys(self.search_loc,'茅台')
    # 键盘回车事件
    def enter(self):
        self.Enter(self.search_loc)
    # 断言2 茅台
    dy2_loc=(By.XPATH,'/html/body/div[6]/div/div[2]/div[1]/div[2]/a[2]')
    def dy2(self):
        return self.text(self.dy2_loc)
    # 点击商品
    goods_loc=(By.XPATH,'/html/body/div[6]/div/div[2]/div[5]/ul/li[1]/div[2]/div[1]/a/img')
    def goods(self):
        self.click(self.goods_loc)
    # 断言3 商品价格
    dy3_loc=(By.CLASS_NAME,'pri')
    def dy3(self):
        return self.text(self.dy3_loc).replace('￥','')
    # 点击加人购物车
    car_loc=(By.XPATH,'//*[@id="addToCartForDetail"]')
    def car(self):
        self.click(self.car_loc)
    # 断言6
    dy6_loc=(By.XPATH,'//*[@id="u-buy-layId"]/div/div[2]/span')
    def dy6(self):
        return self.text(self.dy6_loc)
    # 查看购物车
    select_loc=(By.XPATH,'//*[@id="u-buy-layId"]/div/div[3]/a[2]')
    def select(self):
        self.click(self.select_loc)
    # 断言7 我的购物车
    dy7_loc=(By.XPATH,'//*[@id="cart_container"]/div[2]/div[1]/div[1]')
    def dy7(self):
        return self.text(self.dy7_loc)
    # 点击去结算
    settlement_loc=(By.XPATH,'//*[@id="cart_container"]/div[3]/div[3]/a[1]')
    def settlement(self):
        self.click(self.settlement_loc)
    # 断言8 确认订单信息
    dy8_loc=(By.XPATH,'/html/body/div[2]/div/div[2]/div[2]/span[2]')
    def dy8(self):
        return self.text(self.dy8_loc)
    # 点击提交订单
    tj_loc=(By.XPATH,'//*[@id="submitOrder"]')
    def tj(self):
        self.click(self.tj_loc)
    # 断言4
    dy4_loc=(By.XPATH,'/html/body/div[4]/div/div[1]/ul/li[1]')
    def dy4(self):
        return self.text(self.dy4_loc)
    # 点击我的订单
    dingdan_loc=(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a')
    def dingdan(self):
        self.click(self.dingdan_loc)
    # 断言5 支付金额
    dy5_loc=(By.XPATH,'/html/body/div[5]/div[3]/div[3]/div/div/div[1]/table/tbody/tr/td[3]/p[1]')
    def dy5(self):
        return self.text(self.dy5_loc).replace('¥','')



    def jiuxian_search(self):
        self.jiuxian_login()
        # 搜索
        self.search()
        # 回车事件
        self.enter()
        # 断言2
        self.dy2()
        print(self.dy2())
        assert self.dy2() == "茅台"
        # 点击商品
        self.goods()
        time.sleep(2)
        self.switch()
        # 断言3
        a=self.dy3()
        print(self.dy3())
        assert self.dy3() == "4794.00"
        # 加入购物车
        self.car()
        # 断言6
        self.dy6()
        print(self.dy6())
        assert self.dy6() == "已成功加入购物车"
        # 查看购物车
        self.select()
        self.switch()
        self.dy7()
        print(self.dy7())
        time.sleep(3)
        # 点击结算
        self.settlement()
        self.dy8()
        print(self.dy8())
        assert self.dy8() == "确认订单信息"
        time.sleep(2)
        self.gundong()
        time.sleep(3)

        self.tj()
        # 断言4
        self.dy4()
        print(self.dy4())
        # 我的订单
        self.dingdan()
        self.switch()
        # 断言5
        self.dy5()
        print(self.dy5())
        assert float(self.dy5()) == float(a)